External 1-bit Input/Output with Direction Register
Typical usage of the bean in user's code.
Typical Usage:
Assume the bean name "EBit1".
Some examples of typical usage of this bean are the following:
(1)
The direction of the bean is set to input.
MAIN.C
void main(void)
{
/* Wait until logical "1" is on the pin */
while( !EBit1_GetVal() );
:
}
(2)
The direction of the bean is set to output.
MAIN.C
void main(void)
{
for (;;) {
EBit1_NegVal(); // Invert output level on the pin
}
}
(3)
This example emulates open drain output pin. The direction of the bean is set to input/output
and the safe mode is disabled. External pull-up resistor should be connected to the pin.
MAIN.C
void main(void)
{
/* Set input mode. */
EBit1_SetDir(FALSE);
/* Logical "1" is on the pin */
:
/* Set output mode */
EBit1_SetDir(TRUE);
/* Set output value to "0" */
EBit1_ClrVal();
/* Logical "0" is on the pin */
}
(4)
This example emulates open drain output pin. The direction of the bean is set to input/output
and the safe mode is enabled. External pull-up resistor should be connected to the pin.
MAIN.C
void main(void)
{
/* Set input mode */
EBit1_SetDir(FALSE);
/* Logical "1" is on the pin */
/* Set output value to "0", which will be
applied when the bean will be set to output mode */
EBit1_ClrVal();
:
/* Set output mode */
EBit1_SetDir(TRUE);
/* Logical "0" is on the pin */
}
For more about typical usage of the bean code please refer to the page Bean Code Typical Usage.